<?php
/**
 * fly
 * Copyright By 5920Team (http://www.5920.me)
 * User: yu@5920.me
 * Date: 13-9-27
 * Time: 上午1:49
 */
/**
 * Class C
 * Array Cache File
 */
class C
{
    public static function readFile($fileName, $str)
    {

    }
    public static function writeFile($fileName)
    {

    }



    /**
     * write Cache
     *
     * @param $name
     * @param array $arr
     */
    public static function write($name, Array $arr)
    {
        $str = "<?php\n//[{$name}] Create by fly cache\n";
        $str .= "return array(\n";
        if (empty($arr)) {
            $str .= ");\n";
        }
        else
        {
            foreach($arr as $k => $v)
            {
                $str .= "    '{$k}' => '{$v}', \n";
            }
            $str = substr($str, 0, -3);
            $str .= "\n);\n";
        }

        file_put_contents(FLY_CACHE_PATH . '/' . $name . '.php', $str);
    }

    /**
     * read Cache
     *
     * @param $name
     * @return bool|mixed
     */
    public static function read($name)
    {
        $fileName = FLY_CACHE_PATH . '/' . $name . '.php';
        if(is_file($fileName))
        {
            return require $fileName;
        }
        else
        {
            return false;
        }

    }
}